package com.Ling.Thread.sync;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * File Name: CallableDemo
 * Date: 2020-06-29 15:33
 * Author: liangling
 * Description 使用callable,返回结果，Callable<>泛型指定返回结果类型
 */
public class CallableDemo implements Callable<String> {

    @Override
    public String call() throws Exception {

      int a = 20;
      int b = 30;
      int sum = a+b;
        return "多线程执行结果是"+sum;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {

      FutureTask<String> futureTask =  new FutureTask<>(new CallableDemo());

      new Thread(futureTask).start();
        System.out.println("多线程的线程名是："+Thread.currentThread().getName()+futureTask.get());
    }
}
